import { _decorator, Component, instantiate, Label, Node, Prefab } from 'cc';
import { UIHeader } from '../common/UIHeader';
import { PrefabEnum } from '../common/PrefabEnum';
import { TabLayout } from '../common/TabLayout';
import { EventManager } from '../event/EventManager';
import { UIManager } from '../common/UIManager';

const { ccclass, property } = _decorator;

@ccclass('HeroYardIndex')
export class HeroYardIndex extends Component {
    @property(UIHeader)
    uiHeader:UIHeader
    @property(TabLayout)
    tabLayout:TabLayout
    @property(Node)
    content:Node
    @property(Prefab)
    heroList:Prefab

    @property(Prefab)
    heroGroup:Prefab
    @property(Prefab)
    oasis:Prefab

    start() {
       

        this.uiHeader.setData('英雄别院')

        this.tabLayout.setData(['我的英雄卡牌','英雄编组','占领的绿洲'])
        EventManager.instance.on('我的英雄卡牌', this.onMyCard, this )
        EventManager.instance.on('英雄编组', this.onGroup, this )
        EventManager.instance.on('占领的绿洲', this.onOasis, this )
        EventManager.instance.on('英雄别院close', this.onClose, this)

        this.onMyCard()

    }

    onMyCard(){
        console.log('onMyCard')
        this.content.destroyAllChildren()
        let node = instantiate(this.heroList)
        this.content.addChild(node)
    }

    onGroup(){
        console.log('onGroup')
        this.content.destroyAllChildren()
        let node = instantiate(this.heroGroup)
        this.content.addChild(node)
    }

    onOasis(){
        console.log('onOasis')
        this.content.destroyAllChildren()
        let node = instantiate(this.oasis)
        this.content.addChild(node)
    }

    onClose(){
        UIManager.instance.closeUI(PrefabEnum.HeroYard)
    }

    
}


